package stage1.module5.Q3;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;
import java.util.function.Function;

public class Main {

    public static void main(String[] args) {
        Function<List<Integer>, Double> fun1 =
                o -> o.stream()
                        // 映射到IntStream
                        .mapToInt(Integer::intValue)
                        // 计算平均
                        .average()
                        // 提供默认值
                        .orElse(0.0d);

        Function<Map<String, Integer>, List<Integer>> fun2 = o -> new ArrayList<>(o.values());

        Map<String, Integer> students = new HashMap<>();
        students.put("岑小村", 59);
        students.put("谷天洛", 82);
        students.put("渣渣辉", 98);
        students.put("蓝小月", 65);
        students.put("皮几万", 70);

        double avg = fun1.apply(fun2.apply(students));
        System.out.println("所有学生的平局成绩为：" + avg);
    }
}
